package main

import "fmt"

// 找出数组中和为指定值的两个元素的下标，比如从数组[1, 3, 5, 7, 8]中找出和为8的两个元素的下标分别为(0,3)和(1,2)
func findTowSum(nums []int, target int) [][]int {
	result := [][]int{}
	for i := 0; i < len(nums)-1; i++ {
		for j := i + 1; j < len(nums); j++ {
			if nums[i]+nums[j] == target {
				result = append(result, []int{i, j})
			}
		}
	}
	return result
}
func main() {
	nums := []int{1, 3, 5, 7, 8}
	target := 8
	indices := findTowSum(nums, target)
	if len(indices) > 0 {
		fmt.Println("和为", target, "的两个元素的下标为：")
		for _, pair := range indices {
			fmt.Println(pair)
		}
	} else {
		fmt.Println("找不到和为", target, "的两个元素的下标")
	}
}
